
/**************************************************************************
 * @doc CORE
 * @module scalls.C |
 * Source code for displaying the configuration tables in setup
 * array.
 *
 * Product     :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :
 * <nl>Notes       :
 *
 * @head3 Core Functions |
 * @index | Core
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 *
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form
 * or by any means whether electronic, mechanical, magnetic, optical,
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
$Log:  $
 * ------------------------------------------------------------------------
 ********************************************************************************/

#define VSSCALLS_C
#include <project.h>

//#include <beetle.h>
//#include <beetleplug.h>

#include <stdlib.h>
#include <aclconio.h>
#include <dbmgr.h>
#include <string.h>
#include <aclstr.h>
#include <aclutil.h>
#include <applidl.h>
#include <message.h>
#include <acldev.h>

/** /#define DEBUG_VSSCALLS*/
#ifdef DEBUG_VSSCALLS
#define DEBUG_95
#endif

#include <define.h>
#include <scalls.h>
#include <pscalls.h>
#include <tran.h>
#include <table.h>      /* For inGetFunctionPointer() prototype */
#include <sizes.h>
#include <gds.h>
#include <cst.h>
#include <bdt.h>
#include <hdt.h>
#include <tblutil.h>
#include <tct.h>
#include <msg.h>
#include <msgfuncs.h>
#include <util.h>
#include <mem.h>
#include <file.h>
#include <entry.h>
#include <ui.h>
#include <spdebug.h>
#include <validt.h>
#include <confio.h>
#include <logo.h>
#include <codesec.h>

#ifdef _TARG_68000
#define BIT_FIELD_LENGTH        16
#endif
#ifdef __arm
#define BIT_FIELD_LENGTH        32
#endif

#define KEY_OK  2

extern char szTempMsg[MESSAGE_SIZE + 1];
/*********************************************************************************************
* @func int | inGetRecordCount |
*       Returns the number of records in a data file
*
* @parm char * | pszFileName |
*       data file name
*
* @parm int | inRecordSize |
*       Size of the data record
*
* @rdesc return values.
* @flag int    |  Number of records
* @end
**********************************************************************************************/
int inGetRecordCount(char* pszFileName,int inRecordSize) {
    long lnSize;

    /** /pdebug(("--inGetRecCnt--"));*/
    lnSize = lnGetFileSize(pszFileName);
    return((int) ((lnSize - GEN_VER_SIZE) / (long) inRecordSize));
}

/*********************************************************************************************
* @func int | inCredDebBatchExists |
*       Determines if a batch exists by checking the HDT independent batch flag
*
* @parm RecordList *|prlRecordList |
*       The Configuration file
*
* @parm int | inRecordIndex |
*       The record in the configuration data file
*
* @parm int | inFieldIndex |
*       The field location in the record
*
* @parm char * | pchValue |
*
*
* @rdesc return values.
* @flag int    |  VS_TRUE or VS_FALSE
* @end
**********************************************************************************************/
int inCredDebBatchExists(RecordList* prlRecordList,int inRecordIndex,int inFieldIndex,char* pchValue) {
    int inFieldPos,
    inFieldSize;
    int inResult = VS_FALSE;

    /** /pdebug (("--inCredDebBatchExists--"));*/
    /** /pdebug (("inFieldIndex = %d", inFieldIndex));*/
    /** /pdebug (("Value = %d",*((short*)pchValue)));*/

    if ((inResult = inLoadConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize, inRecordIndex, prlRecordList->pchRecordPtr)) == VS_SUCCESS) {
        /** /pdebug(("record found"));*/

        if (inFieldIndex == -1) {
            void* pstHDTRec = (void*) (prlRecordList->pchRecordPtr);
            registerHDT(pstHDTRec);

            if (fGetIndependentBatchFromStruct(pstHDTRec) && (fGetCredDebHostFromStruct(pstHDTRec)))
                inResult = VS_TRUE;
        } else {
            inFieldPos = (&prlRecordList->psrFieldDefinitionPtr[inFieldIndex])->inFieldPos;
            /* pdebug (("inFieldPos = %d", inFieldPos)); */
            inFieldSize = (&prlRecordList->psrFieldDefinitionPtr[inFieldIndex])->inFieldSize;
            /* pdebug (("inFieldSize = %d", inFieldSize)); */
            if (!memcmp(prlRecordList->pchRecordPtr + inFieldPos, pchValue, inFieldSize)) {
                /* pdebug(("Host %d valid", inRecordIndex)); */
                inResult = VS_TRUE;
            }
        }
    }

    /** /pdebug(("inResult %i", inResult));*/

    return(inResult);
}

/*********************************************************************************************
* @func int | inIndBatchExists |
*       Determines if host has a separate batch by checking the HDT independent batch flag
*
* @parm RecordList *|prlRecordList |
*       The Configuration file
*
* @parm int | inRecordIndex |
*       The record in the configuration data file
*
* @parm int | inFieldIndex |
*       The field location in the record
*
* @parm char * | pchValue |
*
*
* @rdesc return values.
* @flag int    |  VS_TRUE or VS_FALSE
* @end
**********************************************************************************************/
int inIndBatchExists(RecordList* prlRecordList,int inRecordIndex,int inFieldIndex,char* pchValue) {
    int inFieldPos,
    inFieldSize;
    int inResult = VS_FALSE;

    /** /pdebug (("--inIndBatchExists--"));*/
    /** /pdebug (("inFieldIndex = %d", inFieldIndex));*/
    /** /pdebug (("Value = %d",*((short*)pchValue)));*/

    if ((inResult = inLoadConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize, inRecordIndex, prlRecordList->pchRecordPtr)) == VS_SUCCESS) {
        /** /pdebug(("record found"));*/
        if (inFieldIndex == -1) {
            void* pstHDTRec = (void*) (prlRecordList->pchRecordPtr);
            registerHDT(pstHDTRec);

            if (fGetIndependentBatchFromStruct(pstHDTRec))
                inResult = VS_TRUE;
        } else {
            inFieldPos = (&prlRecordList->psrFieldDefinitionPtr[inFieldIndex])->inFieldPos;
            /* pdebug (("inFieldPos = %d", inFieldPos)); */
            inFieldSize = (&prlRecordList->psrFieldDefinitionPtr[inFieldIndex])->inFieldSize;
            /* pdebug (("inFieldSize = %d", inFieldSize)); */
            if (!memcmp(prlRecordList->pchRecordPtr + inFieldPos, pchValue, inFieldSize)) {
                /* pdebug(("Host %d valid", inRecordIndex)); */
                inResult = VS_TRUE;
            }
        }
    }

    /** /pdebug(("inResult %i", inResult));*/

    return(inResult);
}

/*********************************************************************************************
* @func int | inCkHostExists |
*       Determines if a host does check processing by checking the HDT check host flag
*
* @parm RecordList *|prlRecordList |
*       The Configuration file
*
* @parm int | inRecordIndex |
*       The record in the configuration data file
*
* @parm int | inFieldIndex |
*       The field location in the record
*
* @parm char * | pchValue |
*
*
* @rdesc return values.
* @flag int    |  VS_TRUE or VS_FALSE
* @end
**********************************************************************************************/
int inCkHostExists(RecordList* prlRecordList,int inRecordIndex,int inFieldIndex,char* pchValue) {
    int inFieldPos,
    inFieldSize;
    int inResult = VS_FALSE;

    /** /pdebug (("--inCkHostExists--"));*/
    /** /pdebug (("inFieldIndex = %d", inFieldIndex));*/
    /** /pdebug (("Value = %d",*((short*)pchValue)));*/

    if ((inResult = inLoadConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize, inRecordIndex, prlRecordList->pchRecordPtr)) == VS_SUCCESS) {
        /** /pdebug(("record found"));*/
        if (inFieldIndex == -1) {
            registerHDT(prlRecordList->pchRecordPtr);

            if (fGetCheckHostFromStruct(prlRecordList->pchRecordPtr))
                inResult = VS_TRUE;
        } else {
            inFieldPos = (&prlRecordList->psrFieldDefinitionPtr[inFieldIndex])->inFieldPos;
            /* pdebug (("inFieldPos = %d", inFieldPos)); */
            inFieldSize = (&prlRecordList->psrFieldDefinitionPtr[inFieldIndex])->inFieldSize;
            /* pdebug (("inFieldSize = %d", inFieldSize)); */
            if (!memcmp(prlRecordList->pchRecordPtr + inFieldPos, pchValue, inFieldSize)) {
                /* pdebug(("Host %d valid", inRecordIndex)); */
                inResult = VS_TRUE;
            }
        }
    }

    /** /pdebug(("inResult %i", inResult));*/

    return(inResult);
}

/*********************************************************************************************
* @func int | inHFTHostExists |
*       Determines if a host exists
*
* @parm RecordList *|prlRecordList |
*       The Configuration file
*
* @parm int | inRecordIndex |
*       The record in the configuration data file
*
* @parm int | inFieldIndex |
*       The field location in the record
*
* @parm char * | pchValue |
*
*
* @rdesc return values.
* @flag int    |  VS_TRUE or VS_FALSE
* @end
**********************************************************************************************/
int inHFTHostExists(RecordList* prlRecordList,int inRecordIndex,int inFieldIndex,char* pchValue) {
    int inFieldPos,
    inFieldSize;
    int inResult = VS_FALSE;

    /** /pdebug (("--inHFTHostExists--"));*/
    /** /pdebug (("inFieldIndex = %d", inFieldIndex));*/
    /** /pdebug (("Value = %d",*((short*)pchValue)));*/

    if ((inResult = inLoadConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize, inRecordIndex, prlRecordList->pchRecordPtr)) == VS_SUCCESS) {
        /** /pdebug(("record found"));*/

        if (inFieldIndex == -1)
            inResult = VS_TRUE;
        else {
            inFieldPos = (&prlRecordList->psrFieldDefinitionPtr[inFieldIndex])->inFieldPos;
            /** / pdebug (("inFieldPos = %d", inFieldPos)); */
            inFieldSize = (&prlRecordList->psrFieldDefinitionPtr[inFieldIndex])->inFieldSize;
            /** / pdebug (("inFieldSize = %d", inFieldSize)); */
            if (!memcmp(prlRecordList->pchRecordPtr + inFieldPos, pchValue, inFieldSize)) {
                /** / pdebug(("Host %d valid", inRecordIndex)); */
                inResult = VS_TRUE;
            }
        }
    }

    /** /pdebug(("inResult %i", inResult));*/

    return(inResult);
}


/*********************************************************************************************
* @func int | inCSTExists |
*       Determines if a Currency Symbol table exist
*
* @parm RecordList *|prlRecordList |
*       The Configuration file
*
* @parm int | inRecordIndex |
*       The record in the configuration data file
*
* @parm int | inFieldIndex |
*       The field location in the record
*
* @parm char * | pchValue |
*
*
* @rdesc return values.
* @flag int    |  VS_TRUE or VS_FALSE
* @end
**********************************************************************************************/
int inCSTExists(RecordList* prlRecordList,int inRecordIndex,int inFieldIndex,char* pchValue) {
    int inFieldPos,
    inFieldSize;
    int inResult = VS_FALSE;

    /** /pdebug (("--inCSTHostExists--"));*/
    /** /pdebug (("inFieldIndex = %d", inFieldIndex));*/
    /** /pdebug (("Value = %d",*((short*)pchValue)));*/

    if ((inResult = inLoadConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize, inRecordIndex, prlRecordList->pchRecordPtr)) == VS_SUCCESS) {
        /** /pdebug(("record found"));*/

        if (inFieldIndex == -1)
            inResult = VS_TRUE;
        else {
            inFieldPos = (&prlRecordList->psrFieldDefinitionPtr[inFieldIndex])->inFieldPos;
            /** / pdebug (("inFieldPos = %d", inFieldPos)); */
            inFieldSize = (&prlRecordList->psrFieldDefinitionPtr[inFieldIndex])->inFieldSize;
            /** / pdebug (("inFieldSize = %d", inFieldSize)); */
            if (!memcmp(prlRecordList->pchRecordPtr + inFieldPos, pchValue, inFieldSize)) {
                /** / pdebug(("Host %d valid", inRecordIndex)); */
                inResult = VS_TRUE;
            }
        }
    }

    /** /pdebug(("inResult %i", inResult));*/

    return(inResult);
}


/*********************************************************************************************
* @func void | vdDrawCSTNode |
*       Creates a node from the Currency Symbol table
*
* @parm RecordList *|prlRecordList |
*       The Configuration file
*
* @parm RecordNode *|pndCSTNode |
*       Pointer to CST node
*
* @end
**********************************************************************************************/
void vdDrawCSTNode(RecordList* prlRecordList,RecordNode* pndCSTNode) {
    void* cst;
    /** /pdebug(("--vdDrawCSTNode--"));*/

    if (fValidNode((Node *) pndCSTNode)) {
        /** /pdebug(("pszFileName = %s", prlRecordList->pszFileName));*/
        /** /pdebug(("inRecordSize = %d", prlRecordList->inRecordSize));*/
        /** /pdebug(("inRecordIndex = %d", pndCSTNode->inRecordIndex));*/
        //      if ((inLoadConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize,
        //        pndCSTNode->inRecordIndex, prlRecordList->pchRecordPtr)) == VS_SUCCESS)
        if ((inLoadCSTRecFromStruct(pndCSTNode->inRecordIndex, prlRecordList->pchRecordPtr)) == VS_SUCCESS) {
            cst = prlRecordList->pchRecordPtr;
            vdDispMsgAt(CURRENCY_MSG, obDisp.inHomeCol, obDisp.inTablesInputLine, CLR_EOL);
            if (obDisp.blActionFontASC8x21)
                vdDispStrAtRight(szGetCurSymbolFromStruct(cst), obDisp.inTablesInputLine, NO_CLEAR);
            else {
                int inTermCharsPerRow = inGetRowLim(),
                inDummyRow;

                vdCalculateCoord(GRID_4x8_TO_8x21, &inTermCharsPerRow, &inDummyRow);
                vdDisplayAt_ASC8X21(inTermCharsPerRow - strlen(szGetCurSymbolFromStruct(cst)), obDisp.inTablesInputLine, szGetCurSymbolFromStruct(cst), NO_CLEAR);
            }
        }
    }
}

/*********************************************************************************************
* @func void | vdDrawHostNode |
*       Creates a node from the Host configuration table
*
* @parm RecordList *|prlRecordList |
*       The Configuration file
*
* @parm RecordNode *|pndCSTNode |
*       Pointer to Host configuration record node
*
* @end
**********************************************************************************************/
void vdDrawHostNode(RecordList* prlRecordList,RecordNode* pndHostNode) {
    void* hdt;

    /** /pdebug(("--vdDrawHostNode--"));*/
    /*  pdebug(("fValidNode = %d", fValidNode(pndHostNode)));
        pdebug(("pndHostNode = %X", pndHostNode)); */

    if (fValidNode((Node *) pndHostNode)) {
        /** /pdebug(("pszFileName = %s", prlRecordList->pszFileName));*/
        /** /pdebug(("inRecordSize = %d", prlRecordList->inRecordSize));*/
        /** /pdebug(("inRecordIndex = %d", pndHostNode->inRecordIndex));*/
        if ((inLoadConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize, pndHostNode->inRecordIndex, prlRecordList->pchRecordPtr)) == VS_SUCCESS) {
            hdt = prlRecordList->pchRecordPtr;
            registerHDT(hdt);

            vdDispMsgAt(HOST_NAME_MSG, obDisp.inHomeCol, obDisp.inTablesInputLine, CLR_EOL);
            if (obDisp.blActionFontASC8x21)
                vdDispStrAtRight(szGetHostNameFromStruct(hdt), obDisp.inTablesInputLine, NO_CLEAR);
            else {
                int inTermCharsPerRow = inGetRowLim(),
                inDummyRow;

                vdCalculateCoord(GRID_4x8_TO_8x21, &inTermCharsPerRow, &inDummyRow);

		  // Rannie_B1 09132004: Fixed the bug wherein the host name is split into two lines
		  // in multi-language application
                if ((getgrid() == 0) && (get_font_mode() == 2))
		  {
		     vdDisplayAt_ASC8X21(obDisp.inCharsPerRow - strlen(szGetHostNameFromStruct(hdt)), obDisp.inTablesInputLine, szGetHostNameFromStruct(hdt), CLR_EOL);
		  }
		  else
		  {
                   vdDisplayAt_ASC8X21(inTermCharsPerRow - strlen(szGetHostNameFromStruct(hdt)), obDisp.inTablesInputLine, szGetHostNameFromStruct(hdt), NO_CLEAR);
		  }
		  // End Rannie_B1 09132004
            }
        }
    }
}

/*********************************************************************************************
* @func int | inCreateFieldList |
*       Creates a link list of the records in a data file
*
* @parm RecordList *|prlRecordList |
*       The Link List of Configuration files
*
* @parm RecordNode *|pndRecordNode |
*
*
* @parm VS_BOOL** |pfnFieldValidator|
*       Validation function
*
* @parm FieldList **|ppflFieldList |
*       List of fields in data file
*
* @rdesc return values.
* @flag int    |  VS_TRUE or VS_FALSE
* @end
**********************************************************************************************/
int inCreateFieldList(RecordList* prlRecordList,RecordNode* pndRecordNode,VS_BOOL *(*pfnFieldValidator) (void *, int),FieldList** ppflFieldList) {
    int inNumberOfFields;
    int inResult = VS_FAILURE;
    FieldNode* pfnFieldNode;
    FieldList* pflLocalListPtr;
    FieldDefinition* psrFieldDefinitionPtr;

    /** /pdebug(("--inCreateFieldList--"));*/
    *ppflFieldList = pflLocalListPtr = (FieldList *) pliCreateList((long)sizeof(FieldList));
    if (*ppflFieldList) {
        long FieldDefSize = REC_SIZEOF(FieldDefinition);
        psrFieldDefinitionPtr = prlRecordList->psrFieldDefinitionPtr;
        pflLocalListPtr->prlParentRecord = prlRecordList;
        pflLocalListPtr->inRecordNumber = pndRecordNode->inRecordIndex;
        for (inNumberOfFields = 0; psrFieldDefinitionPtr->ucFieldType != FLD_NULL; ++inNumberOfFields) {
            /*
             *      This IF determines which fields are included in the List.
             *          - All fields that are editable or viewable.
             *          - All fields if MEGA PASSWORD is ON.
             */
            if (psrFieldDefinitionPtr->fFieldEditable == 1 || psrFieldDefinitionPtr->fFieldShow == 1 || fGetMegaPassword()) {
                if ((pfnFieldValidator == NULL) || ((*pfnFieldValidator) (pflLocalListPtr, inNumberOfFields) != NULL)) {
                    pfnFieldNode = (FieldNode *) pndCreateNode((long)sizeof(FieldNode));
                    if (pfnFieldNode) {
                        pfnFieldNode->inFieldIndex = inNumberOfFields;
                        if ((inResult = inAddToListEnd((List *) pflLocalListPtr, (Node *) pfnFieldNode)) != VS_SUCCESS) {
                            vdDestroyListAndNodes((List *) pflLocalListPtr);
                            *ppflFieldList = NULL;
                            return(inResult);
                        }
                    } else {
                        ;       /*** This should generate an error condition!   ***/
                    }
                }
            } else {
                ;/** /pdebug(("Field Not Editable-%d",fGetTCTMegaPassword()));*/
            }
            psrFieldDefinitionPtr = (FieldDefinition *) ((unsigned char *) psrFieldDefinitionPtr + FieldDefSize);
        }
        inResult = VS_SUCCESS;
    }

    return(inResult);
}
/*********************************************************************************************
* @func void | vdGetFieldNodeValue |
*       Creates a link list of the records in a data file
*
* @parm RecordList *|prlRecordList |
*       The Link List of Configuration files
*
* @parm int | inFieldIndex |
*       Index into the field table
*
* @parm char * |szFieldValue|
*       Data value
*
* @end
**********************************************************************************************/

void vdGetFieldNodeValue(RecordList* prlRecordList,int inFieldIndex,char* szFieldValue) {
    char* pchValuePtr;
    FieldDefinition* psrFieldDefinitionPtr;
    long FieldDefSize = REC_SIZEOF(FieldDefinition);
#ifdef _TARG_68000
    short FieldValue,
    TempBitsVal;
#endif
#ifdef __arm
    int FieldValue,
    TempBitsVal;
#endif
    //pdebug(("--vdGetFieldNodeValue--"));
    //pdebug(("inFieldIndex = %d", inFieldIndex));

    szFieldValue[0] = '\0';
    //    psrFieldDefinitionPtr = &prlRecordList->psrFieldDefinitionPtr[inFieldIndex];
    psrFieldDefinitionPtr = (FieldDefinition *) ((unsigned char *) prlRecordList->psrFieldDefinitionPtr + (inFieldIndex * FieldDefSize));
    pchValuePtr = &prlRecordList->pchRecordPtr[psrFieldDefinitionPtr->inFieldPos];
    //pdebug(("inFieldPos = %d", psrFieldDefinitionPtr->inFieldPos));

    switch (psrFieldDefinitionPtr->ucFieldType) {
    case    FLD_CHAR:
        szFieldValue[0] = *pchValuePtr;
        szFieldValue[1] = '\0';
        break;

    case    FLD_BYTE:
        sprintf(szFieldValue, SUBSTITUTE_D, *(char *) pchValuePtr);
        break;


    case    FLD_SHORT:
        sprintf(szFieldValue, SUBSTITUTE_D, *(short *) pchValuePtr);
        break;

    case    FLD_LONG:
        sprintf(szFieldValue, SUBSTITUTE_LD, *(long *) pchValuePtr);
        break;

    case    FLD_DBL:
        sprintf(szFieldValue, "%g", *(double *) pchValuePtr);
        break;

    case    FLD_BIT:
        //                pdebug (("FLD_BIT - vdGetFieldNodeValue"));
        //                pdebug (("inFieldBitNum=%d",psrFieldDefinitionPtr->inFieldBitNum));
        memcpy(&TempBitsVal, pchValuePtr, INT_SIZE);
        FieldValue = TempBitsVal & (1 << psrFieldDefinitionPtr->inFieldBitNum);
#ifdef _TARG_68000
        //                FieldValue = *(short *)pchValuePtr & (1 << psrFieldDefinitionPtr->inFieldBitNum);
        //                FieldValue = TempBitsVal & (1 << psrFieldDefinitionPtr->inFieldBitNum);
#endif
#ifdef __arm
        //                FieldValue = *(int *)pchValuePtr & (1 << psrFieldDefinitionPtr->inFieldBitNum);
        //                FieldValue = TempBitsVal & (1 << psrFieldDefinitionPtr->inFieldBitNum);
#endif
        //                pdebug (("FieldValue=%d",FieldValue));
        //sprintf(szFieldValue, SUBSTITUTE_D, (*(short *)pchValuePtr & (1 << psrFieldDefinitionPtr->inFieldBitNum)) != 0);
        sprintf(szFieldValue, SUBSTITUTE_D, FieldValue);
        //                pdebug (("szFieldValue=%s",szFieldValue));
        break;

    case    FLD_STR:
        strlcpy(szFieldValue, pchValuePtr, psrFieldDefinitionPtr->inFieldSize);
        break;

    default:

                    ;
    }

    //pdebug(("szFieldValue = %s", szFieldValue));
}
void vdGetFieldNodeDisplayValue(RecordList* prlRecordList,int inFieldIndex,char* szFieldValue) {
    int inFieldID;
    char szLocBuf[6 + 1];
    char* pchValuePtr;
    FieldDefinition* psrFieldDefinitionPtr;
    long FieldDefSize = REC_SIZEOF(FieldDefinition);
    short shFieldValue = 0;
    char szOn[MESSAGE_SIZE + 1],
    szOff[MESSAGE_SIZE + 1];
    PFI_SH_PSZ pinDisplayFunction;

    //pdebug(("--vdGetFieldNodeDisplayValue--"));

    //pdebug (("inFieldIndex=%d",inFieldIndex));
    szFieldValue[0] = '\0';
    //    psrFieldDefinitionPtr = &prlRecordList->psrFieldDefinitionPtr[inFieldIndex];
    psrFieldDefinitionPtr = (FieldDefinition *) ((unsigned char *) prlRecordList->psrFieldDefinitionPtr + (inFieldIndex * FieldDefSize));
    pchValuePtr = &prlRecordList->pchRecordPtr[psrFieldDefinitionPtr->inFieldPos];
    //LOG_HEX_Buf ((unsigned char *)prlRecordList->pchRecordPtr+136, 8, "pchRecordPtr Data");
    //pdebug(("inFieldPos = %d", psrFieldDefinitionPtr->inFieldPos));
    if ((psrFieldDefinitionPtr->chFieldIOFmt != INPUT_HIDE_NUMS) && (psrFieldDefinitionPtr->chFieldIOFmt != INPUT_HIDE_ALNUMS)) {
        //pdebug(("inFieldType = %X", psrFieldDefinitionPtr->ucFieldType));
        switch (psrFieldDefinitionPtr->ucFieldType) {
        case    FLD_CHAR:
            szFieldValue[0] = *pchValuePtr;
            szFieldValue[1] = '\0';
            break;

        case    FLD_BYTE:
            sprintf(szFieldValue, SUBSTITUTE_D, *(char *) pchValuePtr);
            break;

        case    FLD_SHORT:
            shFieldValue = *(short *) pchValuePtr;
            //pdebug (("shFieldValue=%d",shFieldValue));
            sprintf(szFieldValue, SUBSTITUTE_D, shFieldValue);
            break;

        case    FLD_INT:
            shFieldValue = *(int *) pchValuePtr;
            sprintf(szFieldValue, SUBSTITUTE_D, shFieldValue);
            break;

        case    FLD_LONG:
            sprintf(szFieldValue, SUBSTITUTE_LD, *(long *) pchValuePtr);
            break;

        case    FLD_DBL:
            sprintf(szFieldValue, "%g", *(double *) pchValuePtr);
            break;

        case    FLD_BIT:
             {
#ifdef _TARG_68000
                short FieldValue,
                TempBitsVal;
#endif
#ifdef __arm
                int FieldValue,
                TempBitsVal;
#endif

                //                pdebug (("FLD_BIT - vdGetFieldNodeDisplay"));
                vdGetMessageFromFile(MSG_ON, szOn);
                vdGetMessageFromFile(MSG_OFF, szOff);
                //                pdebug (("inFieldBitNum=%d",psrFieldDefinitionPtr->inFieldBitNum));
                memcpy(&TempBitsVal, pchValuePtr, INT_SIZE);
                //                pdebug (("TempBitsVal = %x",TempBitsVal));
#ifdef _TARG_68000
                //                FieldValue = *(short *)pchValuePtr & (1 << psrFieldDefinitionPtr->inFieldBitNum);
                //                FieldValue = TempBitsVal & (1 << psrFieldDefinitionPtr->inFieldBitNum);
#endif
#ifdef __arm
                //                FieldValue = *(int *)pchValuePtr & (1 << psrFieldDefinitionPtr->inFieldBitNum);
                //                FieldValue = TempBitsVal & (1 << psrFieldDefinitionPtr->inFieldBitNum);
#endif
                FieldValue = TempBitsVal & (1 << psrFieldDefinitionPtr->inFieldBitNum);
                //                pdebug (("FieldValue=%d",FieldValue));
                if (FieldValue) {
                    strcpy(szFieldValue, szOn);
                    shFieldValue = 1;
                } else {
                    strcpy(szFieldValue, szOff);
                    shFieldValue = 0;
                }
                break;
            }

        case    FLD_STR:
            strlcpy(szFieldValue, pchValuePtr, psrFieldDefinitionPtr->inFieldSize);
            break;

        default:
            pdebug(("Undefined Field Type"));
        }
    } else {
        strcpy(szLocBuf, "******");
        strcpy(szFieldValue, szLocBuf);
    }

    // Pick List Display
    if (psrFieldDefinitionPtr->fAltEntry) {
        if (psrFieldDefinitionPtr->shFieldFuncID != NO_VALIDATION) {
            inFieldID = (int) psrFieldDefinitionPtr->shFieldFuncID + 1;
            //pdebug (("inFieldID=%d",inFieldID));
            if ((pinDisplayFunction = (PFI_SH_PSZ) inGetFunctionPointer(inFieldID)) != NULL) {
                //pdebug (("shFieldValue=%d",shFieldValue));
                (pinDisplayFunction) (shFieldValue, szFieldValue);
            }
        }
    }

    //pdebug(("szFieldValue = %s", szFieldValue));
}

/*********************************************************************************************
* @func void | vdRotatingDisplay |
*       This function should only be entered if the the text to
*        be displayed is greater than the screen width and if the
*        terminal has a one or 2 line display. It automatically
*        scrolls the display.
*
* @parm char * |pchDispBuf|
*       Pointer to display buffer
*
* @end
**********************************************************************************************/

void vdRotatingDisplay(char* pchDispBuf) {
    int inCharOffset = 0;
    VS_BOOL fExitFunction = VS_FALSE;
    int inLeft,
    inTop,
    inRight,
    inBottom;
    int inRowLim = inGetRowLim();

    //pdebug(("--vdRotatingDisplay--"));

    wherewin(&inLeft, &inTop, &inRight, &inBottom);
    window(obDisp.inHomeCol, obDisp.inTitleLine, inRowLim, obDisp.inTablesInputLine);

    vdTimeAndDisplay(pchDispBuf + inCharOffset, DELAY_SCROLLING_TICKS);

    do {
        vdTimeAndDisplay(pchDispBuf + inCharOffset, DELAY_SCROLLING_TICKS);

        if (KBHIT() == 0) {
            if ((unsigned) inCharOffset < strlen(pchDispBuf) - obDisp.inCharsPerRow)
                inCharOffset++;
            else
                inCharOffset = 0;
        } else
            fExitFunction = VS_TRUE;
    } while (fExitFunction == VS_FALSE);

    window(inLeft, inTop, inRight, inBottom);
}

/*********************************************************************************************
* @func void |  vdSingleLineRotation |
*       When the the field name and field value are greater
*       than the screen width it is desired to automatically
*       scroll for terminal types with a single or 2 line
*       display. For other terminal types the text
*       should continue onto the next line.
*
*       NOTE:  MUST BE MODIFIED TO SUPPORT MIXED FONTS BEFORE USED.
*
* @parm FieldList *|pflFieldList |
*       Pointer to field list
*
* @parm FieldNode *|pndFieldNode |
*       Pointer to field node
*
* @end
**********************************************************************************************/
#if 0 // SEE NOTE ABOVE...
void vdSingleLineRotation(FieldList *pflFieldList, FieldNode *pndFieldNode)
{
    char szLocNULL[1+1];
    char szFieldValue[ MAX_FIELD_SIZE + 1 ];
    char szFileName[ FILENAME_SIZE + 1 ];
    char szDisplayBuffer[ DISP_STR_LEN + MAX_FIELD_SIZE + 1 ];
    int  i;

    //pdebug(("--vdSingleLineRotation--"));

    /* Copy the first four characters from the filename
        If it is a host data file the name will be four characters
        If it is a configuration data file the name will be three characters
        So the decimal point in the fourth position will need to be removed
    */

    memset(szFileName, NULL_CH, sizeof(szFileName));
    strlcpy(szFileName, pflFieldList->prlParentRecord->pszFileName, FILE_SUFFIX_SIZE);
    purge_char(szFileName, '.');
    memset(szLocNULL, NULL_CH, sizeof(szLocNULL));
    vdDisplayAt(obDisp.inHomeCol, obDisp.inTablesInputLine, szLocNULL, CLR_LINE);

    vdGetFieldNodeValue(pflFieldList->prlParentRecord, pndFieldNode->inFieldIndex, szFieldValue);

    vdGetMessageFromThisFile(szFileName, pflFieldList->prlParentRecord->psrFieldDefinitionPtr[pndFieldNode->inFieldIndex].inFieldName, szDisplayBuffer);

    if (strlen(szDisplayBuffer) + strlen(szFieldValue) + 2 <= (unsigned)obDisp.inCharsPerRow)
    {
        int inLine = (obDisp.inTablesInputLine - 1);

        vdDisplayAt(obDisp.inHomeCol, inLine, szDisplayBuffer, CLR_LINE);
        vdDispStrAtRight(szFieldValue, inLine, NO_CLEAR);
    }
    else
    {
        sprintf(szDisplayBuffer+strlen(szDisplayBuffer), "  %s", szFieldValue);

        for (i = 0; i < obDisp.inCharsPerRow;i++)
           strcat(szDisplayBuffer, " ");
        vdRotatingDisplay(szDisplayBuffer);
    }
}
#endif

/*********************************************************************************************
* @func void |  vdDisplayFieldNode |
*       Display the field name and data. If data is longer than one line, data can be
*       panned.
*
* @parm FieldList *|pflFieldList |
*       Pointer to field list
*
* @parm FieldNode *|pndFieldNode |
*       Pointer to field node
*
* @end
**********************************************************************************************/

void vdDisplayFieldNode(FieldList* pflFieldList,FieldNode* pndFieldNode) {
    int x1,
    y1,
    x2,
    y2;
    int inTermCharsPerRow;
    char szFieldValue[MAX_BUFFER_SIZE + 1];
    char szFileName[FILENAME_SIZE + 1];
    char szDisplayBuffer[DISP_STR_LEN + 1];
    FieldDefinition* psrFieldDefinitionPtr;
    long FieldDefSize = REC_SIZEOF(FieldDefinition);

    //pdebug(("--vdDisplayFieldNode--"));

    /* Copy the first four characters from the filename
        If it is a host data file the name will be four characters
        If it is a configuration data file the name will be three characters
        So the decimal point in the fourth position will need to be removed
    */
    memset(szFileName, 0x00, sizeof(szFileName));
    strlcpy(szFileName, (char *) &pflFieldList->prlParentRecord->pszFileName, FILE_SUFFIX_SIZE);
    purge_char(szFileName, '.');
    vdGetFieldNodeDisplayValue(pflFieldList->prlParentRecord, pndFieldNode->inFieldIndex, szFieldValue);
    psrFieldDefinitionPtr = (FieldDefinition *) ((unsigned char *) pflFieldList->prlParentRecord->psrFieldDefinitionPtr + (pndFieldNode->inFieldIndex * FieldDefSize));
    vdGetMessageFromThisFile(szFileName, psrFieldDefinitionPtr->inFieldName, szDisplayBuffer);

    /*
     *      Display will be done in ASCII 8x21 Font
     *      If Action Font differs, we must convert to 8x21
     */
    inTermCharsPerRow = inGetRowLim();
    if (!obDisp.blActionFontASC8x21) {
        int inDummyRow = 1;

        vdCalculateCoord(GRID_4x8_TO_8x21, &inTermCharsPerRow, &inDummyRow);
    }

    /*
     *      Clear Screen
     */
    wherewin(&x1, &y1, &x2, &y2);
    window(x1, y1 + (obDisp.inCharsPerColumn == 4 ? 1 : 2), x2, y2);
    clrscr();
    window(x1, y1, x2, y2);

    /*
     *      Display Title
     */
    if (strlen(szDisplayBuffer) > (unsigned) inTermCharsPerRow)
        szDisplayBuffer[inTermCharsPerRow] = 0x00;
    if (obDisp.blActionFontASC8x21)
        vdDisplayAt(obDisp.inHomeCol, obDisp.inTablesInputLine, szDisplayBuffer, NO_CLEAR);
    else
        vdDisplayAt_ASC8X21(obDisp.inHomeCol, obDisp.inTablesInputLine + 1, szDisplayBuffer, NO_CLEAR);

    /*
     *      Display Data
     */
    vdDisp3200CfgVal(inTermCharsPerRow, obDisp.inHomeCol, (obDisp.inTablesInputLine + 1), szFieldValue, CLR_EOL);
}

void vdDisp3200CfgVal(int inLineLen,int inCol,int inLine,char* szBuf,int inClr) {
    int inCnt;
    int inIncr = 0;
    int inSLen = (int) strlen(szBuf);
    int inDivRes = inSLen / inLineLen;
    char szDispBuf[MAX_CHARS_PER_ROW + 1];

    if (inDivRes == 0)
        inCnt = 1;
    else if (inDivRes == 1) {
        inCnt = 1;
        if (inSLen > inLineLen)
            inCnt = 2;
    } else if (inDivRes == 2) {
        inCnt = 2;
        if (inSLen > (inLineLen * 2))
            inCnt = 3;
    } else if (inDivRes == 3) {
        inCnt = 3;
        if (inSLen > (inLineLen * 3))
            inCnt = 4;
    } else if (inDivRes == 4 && obDisp.blActionFontASC8x21) {
        inCnt = 3;
        if (inSLen > (inLineLen * 3))
            inCnt = 5;
    } else {
        return; /* out-of-range */
    }

    for (inIncr = 0; inIncr < inCnt; inIncr++) {
        strlcpy(szDispBuf, (char *) (szBuf + (inIncr * inLineLen)), inLineLen);
        if (obDisp.blActionFontASC8x21)
            vdDisplayAt(inCol, inLine, szDispBuf, inClr);
        else
            vdDisplayAt_ASC8X21(inCol, inLine + 1, szDispBuf, inClr);
        inLine++;
    }
}

/***** NOTE BELOW FUNCTION DOES NOT SUPPORT GRAPHICAL LANGUAGES ******/

void vdDisplayMultiLineField(int inTermCharsPerRow,int inLine,char* szDisplayBuffer,char* szFieldValue) {
    int x1,
    y1,
    x2,
    y2;
    char szMsgBuf[MESSAGE_SIZE + 1];
    char szLineBuf[4][MESSAGE_SIZE + 1];

    wherewin(&x1, &y1, &x2, &y2);
    window(obDisp.in3200BarCol, obDisp.inTitleLine, obDisp.inCharsPerRow, obDisp.inCharsPerColumn);
    clrscr();
    window(obDisp.inHomeCol, obDisp.inTitleLine, obDisp.inCharsPerRow, obDisp.inCharsPerColumn);
    vdGetMessageFromFile(O3200_PAN_EXIT_MSG, szMsgBuf);
    vdDisplayAt(6, obDisp.inStatusLine, szMsgBuf, NO_CLEAR);
    window(obDisp.inHomeCol, inLine + 1, obDisp.inCharsPerRow, inLine + 1);
    view_buffer(szFieldValue, (obDisp.inCharsPerRow), KM_h);
    szFieldValue[inTermCharsPerRow] = NULL_CH;
    vdDisplayAt(obDisp.inHomeCol, inLine + 1, szFieldValue, NO_CLEAR);
    /* 3200: parse keys, display in right window */
    vdLoad3200Opt(szLineBuf, O3200_TBL_EDIT_KEYS_MSG);
    vdCreateOptWin3200(szLineBuf);
    /*
     * restore original pane...
     */
    window(x1, y1, x2, y2);
}

int inCreateRecordList(const char* pszRecordType,RecordList** pprlRecordList,PFI_RL_IN_IN_CP pfnRecordValidator,int inFieldIndex,char* pchValue) {
    char pszFileName[FILENAME_SIZE + 1];
    int inNumberOfRecords;
    int  inResult = VS_FAILURE,
    inRecLen;
    int inTitleFieldIndex;
    int inRecordsAdded = 0;
    RecordNode* pndRecordNode;
    RecordList* prlLocalListPtr;

    pdebug(("--inCreateRecordList--"));



    strcpy(pszFileName, pszRecordType);
    strcat(pszFileName, DAT_SUFFIX);
    //pdebug(("pszFileName = %s", pszFileName));



    *pprlRecordList = prlLocalListPtr = (RecordList *) pliCreateList((long)sizeof(RecordList));
    if (*pprlRecordList) {

        if ((inRecLen = inGetRecordDescriptor(pszRecordType, &(prlLocalListPtr->psrFieldDefinitionPtr), &inTitleFieldIndex)) > 0) {

            prlLocalListPtr->inTitleFieldIndex = inTitleFieldIndex;
            strcpy(prlLocalListPtr->pszFileName, pszFileName);
            prlLocalListPtr->inRecordSize = inRecLen;
            inNumberOfRecords = inGetRecordCount(pszFileName, inRecLen);
            pdebug(("inNumRecs = %d", inNumberOfRecords));
            prlLocalListPtr->inNumberOfRecords = inNumberOfRecords;
            pdebug(("inRecLen = %d", inRecLen));
            prlLocalListPtr->pchRecordPtr = pchAlloc(inRecLen);
            if (prlLocalListPtr->pchRecordPtr) {

                while (inNumberOfRecords--) {

                    VS_BOOL fValid = VS_TRUE;

                    if (pfnRecordValidator != NULL)
                        fValid = (*pfnRecordValidator) (prlLocalListPtr, inNumberOfRecords, inFieldIndex, pchValue);
                    if (fValid == VS_TRUE) {

                        pndRecordNode = (RecordNode *) pndCreateNode((long)sizeof(RecordNode));
                        if (pndRecordNode) {

                            pndRecordNode->inRecordIndex = inNumberOfRecords;
                            if ((inResult = inAddToListStart((List *) prlLocalListPtr, (Node *) pndRecordNode)) != VS_SUCCESS) {

                                vdFree(prlLocalListPtr->pchRecordPtr);
                                vdDestroyListAndNodes((List *) prlLocalListPtr);
                                *pprlRecordList = NULL_CH;
                                return(inResult);
                            }
                            inRecordsAdded++;
                        } else {
                            /*** This should generate an error condition!   ***/
                            ;pdebug(("pndCreateNode in inCreateRecordList failed"));
                        }
                    }
                }

                inResult = VS_SUCCESS;
                //pdebug(("inRecordsAdded = %d", inRecordsAdded));
            } else {

                vdDestroyListAndNodes((List *) prlLocalListPtr);
                *pprlRecordList = NULL_CH;
                return(inResult);
            }
        } else
            return(VS_ERR);
    }

    return(inRecordsAdded);
}

int inSelectRecord(const char* pszFileName,int (*pfnRecordValidator) (RecordList *, int, int, char*),int inFieldIndex,char* pchValue,void (*pfnDisplayRecord) (RecordList *, RecordNode*),long lnErrorMessage) {
    char szLineBuf[4][MESSAGE_SIZE + 1];
    char szLocNULL[1 + 1];
    int inResult;
    RecordList* prlRecordList;
    int inOptCreated = 0;
    RecordNode* pndRecordNode = NULL_CH;

    //pdebug(("--inSelectRecord--"));


    if ((inResult = inCreateRecordList(pszFileName, &prlRecordList, pfnRecordValidator, inFieldIndex, pchValue)) >= 0) {

        if (inResult > 0) {

            if (inResult > 1) {

                memset(szLocNULL, NULL_CH, sizeof(szLocNULL));
                vdLoad3200Opt(szLineBuf, O3200_TBL_CHOOSE_KEYS_MSG);
                vdCreateOptWin3200(szLineBuf);
                inOptCreated = 1;

                inSelectNode(prlRecordList, (Node * *) &pndRecordNode, pfnDisplayRecord);
                if (obDisp.inCharsPerRow == 25)
                    vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, szLocNULL, CLR_LINE);
            } else
                pndRecordNode = (RecordNode *) prlRecordList->liListInfo.pndHead;
            if (pndRecordNode)
                inResult = pndRecordNode->inRecordIndex;
            else
                inResult = VS_ESCAPE;
        } else {
            vdDisplayMessageFromFile(lnErrorMessage, ERROR_MSG);
            inResult = VS_ESCAPE;
        }

        vdFree((char *) prlRecordList->psrFieldDefinitionPtr);
        vdFree(prlRecordList->pchRecordPtr);
        vdDestroyListAndNodes((List *) prlRecordList);

    }

    if (inOptCreated)
        vdDestroyOptWin3200();

    //pdebug(("inResult from inSelectRecord = %d", inResult));
    return(inResult);
}


int inSelectHFTRecord(char* pszFileName,int (*pfnRecordValidator) (),int inFieldIndex,char* pchValue,void (*pfnDisplayRecord) (),long lnErrorMessage) {
    char szLineBuf[4][MESSAGE_SIZE + 1];
    char szLocNULL[1 + 1];

    int inResult;
    RecordList* prlRecordList;
    int inOptCreated = 0;
    RecordNode* pndRecordNode = NULL_CH;

    //pdebug(("--inSelectHFTRecord--"));

    if ((inResult = inCreateRecordList(pszFileName, &prlRecordList, pfnRecordValidator, inFieldIndex, pchValue)) >= 0) {
        memset(szLocNULL, NULL_CH, sizeof(szLocNULL));

        if (inResult > 0) {
            if (inResult > 1) {
                /** /pdebug(("Multiple hosts"));*/
                /* 3200: parse keys, display in right window */
                vdLoad3200Opt(szLineBuf, O3200_TBL_CHOOSE_KEYS_MSG);
                vdCreateOptWin3200(szLineBuf);
                inOptCreated = 1;

                inSelectNode(prlRecordList, (Node * *) &pndRecordNode, pfnDisplayRecord);
                if (obDisp.inCharsPerRow == 25)
                    vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, szLocNULL, CLR_LINE);
            } else {
                /** /pdebug(("Only one host!"));*/
                pndRecordNode = (RecordNode *) prlRecordList->liListInfo.pndHead;
            }
            if (pndRecordNode) {
                inResult = pndRecordNode->inRecordIndex;
                /** /pdebug(("inResult from inSelectRecord = %d", inResult));*/
            } else
                inResult = VS_ESCAPE;
        } else {
            /** /pdebug(("No hosts"));*/
            vdDisplayMessageFromFile(lnErrorMessage, ERROR_MSG);
            inResult = VS_ERR;
        }
        vdFree((char *) prlRecordList->psrFieldDefinitionPtr);
        vdFree(prlRecordList->pchRecordPtr);
        vdDestroyListAndNodes((List *) prlRecordList);
    }

    if (inOptCreated)
        vdDestroyOptWin3200();

    /** /pdebug(("inResult from inSelectRecord = %d", inResult));*/
    return(inResult);
}

/*-------------------------------------------------------------------------
    Function :    inSelectHost
    Description :
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      0   -------- T_Al_G     Creation.
      1   01/22/96 Ana_C1     added parameters that allows to only display a
                              group of records with a field in common.
--------------------------------------------------------------------------*/
int inSelectHost(int inFieldIndex,char* pchValue,PFI_RL_IN_IN_CP inFunc,long lnErrorMessage) {
    //pdebug(("--inSelectHost--"));
    int inRet = VS_ERR;

    if (*inFunc != NULL)
        inRet = inSelectRecord((const char *) "hdt", inFunc, inFieldIndex, pchValue, &vdDrawHostNode, lnErrorMessage);

    return(inRet);
}

int inSelectHFTHost(int inFieldIndex,char* pchValue,int (*inFunc) ()) {
    //pdebug(("--inSelectHFTHost--"));

    if (inFunc)
        return(inSelectHFTRecord("HDT", inFunc, inFieldIndex, pchValue, vdDrawHostNode, BATCH_EMPTY_MSG));
    else
        return(VS_ERR);
}



/*-------------------------------------------------------------------------
    Function :    inSelectCSTRecord
    Description :
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      1   11/30/98 Page_K1    Remove commented code.
--------------------------------------------------------------------------*/
int inSelectCSTRecord(char* pszFileName,int (*pfnRecordValidator) (),int inFieldIndex,char* pchValue,void (*pfnDisplayRecord) (),long lnErrorMessage) {
    char szLineBuf[4][MESSAGE_SIZE + 1];
    char szLocNULL[1 + 1];
    int inResult;
    RecordList* prlRecordList;
    int inOptCreated = 0;
    RecordNode* pndRecordNode = NULL_CH;

    //pdebug(("--inSelectCSTRecord--"));

    if ((inResult = inCreateRecordList(pszFileName, &prlRecordList, pfnRecordValidator, inFieldIndex, pchValue)) >= 0) {
        memset(szLocNULL, NULL_CH, sizeof(szLocNULL));
        if (inResult > 0) {
            if (inResult > 1) {
                /** /pdebug(("Multiple currencies"));*/
                /* 3200: parse keys, display in right wndow */
                vdLoad3200Opt(szLineBuf, O3200_TBL_CHOOSE_KEYS_MSG);
                vdCreateOptWin3200(szLineBuf);
                inOptCreated = 1;

                inSelectNode(prlRecordList, (Node * *) &pndRecordNode, pfnDisplayRecord);
                if (obDisp.inCharsPerRow == 25)
                    vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, szLocNULL, CLR_LINE);
            } else {
                /** /pdebug(("Only one host!"));*/
                pndRecordNode = (RecordNode *) prlRecordList->liListInfo.pndHead;
            }
            if (pndRecordNode) {
                inResult = pndRecordNode->inRecordIndex;
                /** /pdebug(("inResult from inSelectRecord = %d", inResult));*/
            } else
                inResult = VS_ESCAPE;
        } else {
            /** /pdebug(("No hosts"));*/
            vdDisplayMessageFromFile(lnErrorMessage, ERROR_MSG);
            inResult = VS_ERR;
        }
        vdFree((char *) prlRecordList->psrFieldDefinitionPtr);
        vdFree(prlRecordList->pchRecordPtr);
        vdDestroyListAndNodes((List *) prlRecordList);
    }

    if (inOptCreated)
        vdDestroyOptWin3200();

    /** /pdebug(("inResult from inSelectRecord = %d", inResult));*/
    return(inResult);
}



/*-------------------------------------------------------------------------
    Function :    inSelectCurrency
    Description :
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      0   01/26/95  Ana_C1    Creation.
      1   11/23/98 Page_K1    Use CST table instead of ACT table
      2   11/30/98 Page_K1    Check inFunc.
--------------------------------------------------------------------------*/
int inSelectCurrency(int inFieldIndex,char* pchValue,PFI_RL_IN_IN_CP inFunc) {
    //pdebug(("--inSelectCurrency---"));
    const char* CSTStr = "CST";

    if (inFunc)
        return(inSelectRecord(CSTStr, inFunc, inFieldIndex, pchValue, &vdDrawCSTNode, CST_ERR_MSG));
    else
        return(VS_ERR);
}

void vdDisplayHexRow(char* pchSourceAddr,int inByteCount) {
    int inBytePos;
    int inByteFromRow;
    char szHexByte[8];
    char szHexString[26];
    char szLocBuf[5 + 1];

    for (inBytePos = 0; inBytePos < inByteCount; inBytePos += 8) {
        strcpy(szLocBuf, "%02X:");
        sprintf(szHexString, szLocBuf, inBytePos);

        for (inByteFromRow = 0; (inByteFromRow < 8) && ((inBytePos + inByteFromRow) < inByteCount); inByteFromRow += 2) {
            strcpy(szLocBuf, " %02X");
            sprintf(szHexByte, szLocBuf, *pchSourceAddr++);

            strcat(szHexString, szHexByte);

            strcpy(szLocBuf, "%02X");
            sprintf(szHexByte, szLocBuf, *pchSourceAddr++);
            strcat(szHexString, szHexByte);
        }
        vdDisplayString(szHexString);
        if (inBytePos & 8)
            get_char();
    }
}

int inGetRecordDescriptor(const char* pszRecordType,FieldDefinition** ppsrFieldDefinitionRecord,int* pinTitleFieldIndex) {
    int inRecordSize = 0;
    int inBitFieldCount = BIT_FIELD_LENGTH - 1;
    int inFieldDescriptionFile;
    long lnDescriptionSize;
    int inResult = VS_ERR;
    int inLoadedFine = VS_FALSE;
    FieldDefinition* psrFieldDefinitionPtr = NULL;
    FieldDefinition* psrFieldDefinitionPtrNext = NULL;
    char pszFileName[FILENAME_SIZE + 1];
    short dividend,
    remainder;

    //pdebug(("--inGetRecordDescriptor--"));
    //pdebug(("BIT_FIELD_LENGTH=%d",BIT_FIELD_LENGTH));

#ifdef __arm
    dividend = 4;
#endif
#ifdef _TARG_68000
    dividend = 2;
#endif
    //pdebug (("dividend=%d",dividend));

    strcpy(pszFileName, STATIC_DATA_PATH);
    strcat(pszFileName, pszRecordType);
    strcat(pszFileName, ".FLD");
    //pdebug(("Field Def. File = %s", pszFileName));
    if ((inFieldDescriptionFile = open(pszFileName, O_RDONLY)) != -1) {
        inResult = -2;
        if ((lnDescriptionSize = lseek(inFieldDescriptionFile, 0L, SEEK_END) - GEN_VER_SIZE) > 0L) {
            pdebug(("lnDescriptionSize=%ld", lnDescriptionSize));
            inResult = -3;
            if (lseek(inFieldDescriptionFile, (long) GEN_VER_SIZE, SEEK_SET) != -1L) {
                inResult = -4;
                if ((psrFieldDefinitionPtr = (FieldDefinition *) pchAlloc((int) lnDescriptionSize)) != NULL_CH) {
                    inResult = -5;
                    if (read(inFieldDescriptionFile, (char *) &psrFieldDefinitionPtr[0], (int) lnDescriptionSize) == lnDescriptionSize) {
                        inLoadedFine = VS_TRUE;
                        //pdebug(("\n FLD Loaded Fine"));
                    } else
                        vdFree((char *) psrFieldDefinitionPtr);
                }
            }
        }
        close(inFieldDescriptionFile);
    } else {
        //pdebug(("!Open %s", pszFileName));
        vdSGErrorMessage(TABLES_ERR_MSG);
        return(VS_ERR);
    }

    if (inLoadedFine) {
        long FieldDefSize = REC_SIZEOF(FieldDefinition);
        *pinTitleFieldIndex = 0;
        //        *ppsrFieldDefinitionRecord = psrFieldDefinitionPtr--;
        *ppsrFieldDefinitionRecord = psrFieldDefinitionPtr;
        //        while ((++psrFieldDefinitionPtr)->ucFieldType != FLD_NULL)
        while (psrFieldDefinitionPtr->ucFieldType != FLD_NULL) {
            psrFieldDefinitionPtrNext = (FieldDefinition *) ((unsigned char *) psrFieldDefinitionPtr + FieldDefSize);
            //pdebug (("psrFieldDefinitionPtr=%lx",psrFieldDefinitionPtr));
            //pdebug (("psrFieldDefinitionPtrNext=%lx",psrFieldDefinitionPtrNext));
            //pdebug (("ucFieldType=%d",psrFieldDefinitionPtr->ucFieldType));
            //pdebug (("inRecordSize1=%d",inRecordSize));
            /* Ensure all numeric-type fields start on 2 or 4-byte boundary */
            switch (psrFieldDefinitionPtr->ucFieldType) {
                // These Fields must start on even boundary
            case FLD_SHORT:
            case FLD_BIT:
                if ((remainder = inRecordSize % 2) != 0) {
                    //pdebug (("remainderTE=%d",remainder));
                    inRecordSize += (2 - (remainder % 2));
                    LOG_PRINTFF((0x08L, "Record size on bit is %d   rem %d", inRecordSize, remainder));
                }
                break;
                // These fields must start on a even (SDS) or 4-byte (ADS) boundary
            case FLD_INT:
            case FLD_LONG:
            case FLD_DBL:
                //                case FLD_BIT:
                if ((remainder = inRecordSize % dividend) != 0) {
                    //pdebug (("remainderT4=%d",remainder));
                    inRecordSize += (dividend - (remainder % dividend));
                }
                break;
            }
            psrFieldDefinitionPtr->inFieldPos = inRecordSize;
            if (psrFieldDefinitionPtr->ucFieldType == FLD_BIT) {
                //pdebug (("FLD_BIT"));
                psrFieldDefinitionPtr->inFieldBitNum = inBitFieldCount;
                //                if ((--inBitFieldCount < 0) || (psrFieldDefinitionPtr[1].ucFieldType != FLD_BIT))
                if ((--inBitFieldCount < 0) || (psrFieldDefinitionPtrNext->ucFieldType != FLD_BIT && psrFieldDefinitionPtrNext->ucFieldType != FLD_NULL)) {
                    /*
                     * Reset the bit field counters if we've run out of bits
                     * in this integer or if the field after this one isn't
                     * a bit field.
                     * BUG ALERT! ==> This test treats every bit field
                     * as being one-bit wide. For multi-bit widths this
                     * will not compute the correct offsets for whatever
                     * follows. Have fun!
                     */
                    //pdebug (("inBitFieldCount=%d",inBitFieldCount));
                    //pdebug (("ucFieldType=%d",psrFieldDefinitionPtrNext->ucFieldType));
                    inBitFieldCount = BIT_FIELD_LENGTH - 1;
                    // inBitFieldCount = 63;
                    inRecordSize += INT_SIZE; /* bit map is integer value */
                }
            } else {
                /*
                 * Increment Record Size based on field type, except for
                 * FLD_STR which uses (inFieldSize + 1); inFieldSize now
                 * indicates how many digits/chars to accept for entry:
                 *
                 *      FLD_BYTE, FLD_CHAR      == 1 byte
                 *      FLD_LONG, FLD_DBL       == 4 bytes
                 *      FLD_INT, FLD_SHORT      == 2 bytes
                 */
                switch (psrFieldDefinitionPtr->ucFieldType) {
                case FLD_STR:
                    //pdebug (("FLD_STR"));
                    inRecordSize += (psrFieldDefinitionPtr->inFieldSize + 1);
                    break;
                case FLD_SHARR:
                    //pdebug (("FLD_SHARR"));
                    inRecordSize += (psrFieldDefinitionPtr->inFieldSize);
                    break;
                case FLD_BYTE:
                    //pdebug (("FLD_BYTE"));
                case FLD_CHAR:
                    //pdebug (("FLD_CHAR"));
                    inRecordSize += CHAR_SIZE;
                    break;
                case FLD_LONG:
                    //pdebug (("FLD_LONG"));
                case FLD_DBL:
                    //pdebug (("FLD_DBL"));
                    inRecordSize += LONG_SIZE;
                    break;
                case FLD_INT:
                    //pdebug (("FLD_INT"));
                    inRecordSize += INT_SIZE;
                    break;
                case FLD_SHORT:
                    //pdebug (("FLD_SHORT"));
                    inRecordSize += SHORT_SIZE;
                    break;
                }
            }

            /*
             * If this field holds data that enables the user to pick
             * the correct record to view/edit, then compute its index
             * and return it to the calling function.
             */
            if (psrFieldDefinitionPtr->fFieldTitle) {
                *pinTitleFieldIndex = -(*ppsrFieldDefinitionRecord - psrFieldDefinitionPtr);
                //                        *pinTitleFieldIndex = &psrFieldDefinitionPtr->inFieldName;
            }
            //pdebug (("inRecordSize2=%d",inRecordSize));
            //psrFieldDefinitionPtr += REC_SIZEOF(FieldDefinition);
            psrFieldDefinitionPtr = psrFieldDefinitionPtrNext;
        }
        if ((remainder = inRecordSize % dividend) != 0) {
            //pdebug (("remainderB=%d",remainder));
            inRecordSize += (dividend - (remainder % dividend));
        }
        inResult = inRecordSize;
    }
    //pdebug (("inResult=%d",inResult));
    return(inResult);
}

void vdDisplayRecordNode(RecordList* prlRecordList,RecordNode* pndRecordNode) {
    char szNodeString[64 + 1];
    char szNULL[1 + 1];
    char szTitle[32 + 1];             /* Titles should never be more than this! */

    memset(szNULL, NULL_CH, sizeof(szNULL));

    //pdebug(("--vdDisplayRecordNode--"));
    //pdebug(("pszFileName = %s", prlRecordList->pszFileName));
    if (inLoadConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize, pndRecordNode->inRecordIndex, prlRecordList->pchRecordPtr) == VS_SUCCESS) {
        vdGetFieldNodeDisplayValue(prlRecordList, prlRecordList->inTitleFieldIndex, szTitle);
        //pdebug(("szTitle = %s", szTitle));
    }

    /* For 3200, force title to next line */
    sprintf(szNodeString, "#%d/%d:", pndRecordNode->inRecordIndex + 1, prlRecordList->inNumberOfRecords);

    szTitle[15] = NULL_CH;
    /*
     *      Display in English 8x21 font
     */ {
        int x1,
        y1,
        x2,
        y2;
        int     inDispRow = obDisp. inTablesInputLine,
        inDispCol = obDisp.inHomeCol,
        inDummyCol = 1;

        /*
           *        Clear Display Area
         */
        wherewin(&x1, &y1, &x2, &y2);
        window(x1, y1 + (obDisp.inCharsPerColumn == 4 ? 1 : 2), x2, y2);
        clrscr();
        window(x1, y1, x2, y2);

        if (obDisp.blActionFontASC8x21) {
            vdDisplayAt(inDispCol, inDispRow, szNodeString, NO_CLEAR);
            vdDisplayAt(inDispCol, inDispRow + 1, szTitle, NO_CLEAR);
        } else {
            vdDisplayAt_ASC8X21(inDispCol, inDispRow, szNodeString, NO_CLEAR);
            vdDisplayAt_ASC8X21(inDispCol, inDispRow + 1, szTitle, NO_CLEAR);
        }
    }
}

int inEditField(FieldList* pflFieldList,FieldNode* pfnSelectedField,int* inFieldChgd) {
    char szFieldValue[MAX_CONFIG_FIELD_SIZE + 1];
    char* pchValuePtr;
#ifdef _TARG_68000
    short BitFieldValue,
    TempBitsVal;
#endif
#ifdef __arm
    int BitFieldValue,
    TempBitsVal;
#endif
    int inResult = VS_FAILURE;
    int inRetVal;
    int inFieldID;
    signed int inMenuOption;
    PFI_PSZ pinValFunction;
    PFI_PSZ pinEntryFunction;
    FieldDefinition* psrFieldDefinitionPtr;
    long FieldDefSize = REC_SIZEOF(FieldDefinition);
    char* chNull = 0;
    VS_BOOL fDataEntry = VS_FALSE;

    //pdebug(("--inEditField--"));

    (*inFieldChgd) = 0;

    if (fValidList((List *) pflFieldList) && fValidNode((Node *) pfnSelectedField)) {
        vdDisplayMessageFromFile(EMPTY_STR_ERR_MSG, STATUS_MSG);
        //        psrFieldDefinitionPtr = &pflFieldList->prlParentRecord->psrFieldDefinitionPtr[pfnSelectedField->inFieldIndex];
        psrFieldDefinitionPtr = (FieldDefinition *) ((unsigned char *) pflFieldList->prlParentRecord->psrFieldDefinitionPtr + (pfnSelectedField->inFieldIndex * FieldDefSize));
        pchValuePtr = &pflFieldList->prlParentRecord->pchRecordPtr[psrFieldDefinitionPtr->inFieldPos];
     //   LOG_PRINTFF((0x08L, "Table %x %x	", psrFieldDefinitionPtr->shFieldFuncID, inFieldID));

        while (1) {
            // New UI for pick list fields
            if (psrFieldDefinitionPtr->fAltEntry) {
                //pdebug (("fAltEntry"));
                inResult = VS_FAILURE;

                if (psrFieldDefinitionPtr->shFieldFuncID != NO_VALIDATION) {
                    inFieldID = (int) psrFieldDefinitionPtr->shFieldFuncID;

                    LOG_PRINTFF((0x08L, "Table %x %x	", psrFieldDefinitionPtr->shFieldFuncID, inFieldID));
                    if ((pinEntryFunction = (PFI_PSZ) inGetFunctionPointer(inFieldID)) != NULL) {
                        inResult = (pinEntryFunction) (szFieldValue);
                        fDataEntry = VS_TRUE;
                    } else
                        inResult = VS_SUCCESS;
                }
                // Exit While loop
                if (inResult == VS_FAILURE)
                    break;
                inRetVal = VS_SUCCESS;
            }

            // If fAltEntry NOT Set or Entry Function == NULL_PFI (Display Only)
            // Perform below field entry
            if (fDataEntry == VS_FALSE) {
                /* New user interface for bitfields - begin */
                if (psrFieldDefinitionPtr->ucFieldType == FLD_BIT) {
                    vdDestroyOptWin3200();  /* reset to prior.... */
                    vdDisplayAt(obDisp.inHomeCol, obDisp.inSecondLineCOne, pchGetMsg(SELECT_ON_OFF_MSG15), NO_CLEAR);
                    inMenuOption = obDisp.inDO_ChooseOne(chNull, chNull, pchGetMsg(ON_OFF_MSG5x), 2, NULL_PFI);
                    if (inMenuOption == 1)      /* ON selected */
                        szFieldValue[0] = '1';
                    else if (inMenuOption == 2) /* OFF selected */
                        szFieldValue[0] = '0';
                    else /* CANCEL key hit */
                        break;
                    szFieldValue[1] = '\0';
                    inResult = inRetVal = VS_SUCCESS;
                }
                /* New user interface for bitfields - end */
                else if ((inResult = inEnterWithMessage(NEWVAL_MSG15, VS_FALSE, szFieldValue, psrFieldDefinitionPtr->chFieldIOFmt, psrFieldDefinitionPtr->inFieldSize, NULL)) >= 0)
                    inRetVal = VS_SUCCESS;
            }

            //pdebug (("inResult = %d",inResult));
            if (inResult == VS_ESCAPE)  /* CANCEL key hit or time out during entry */
                break;
            else if (inResult >= 0) {
                /* adding validation function support */
                /* mark fields that have been validated/initted for use in case of CANCEL */
                if (psrFieldDefinitionPtr->shFieldFuncID != NO_VALIDATION) {
                    inRetVal = VS_SUCCESS;
                    inFieldID = (int) psrFieldDefinitionPtr->shFieldFuncID;
                    LOG_PRINTFF((0x08L, "Table %x %x	", psrFieldDefinitionPtr->shFieldFuncID, inFieldID));

                    if ((pinValFunction = (PFI_PSZ) inGetFunctionPointer(inFieldID)) != NULL)
                        inRetVal = (pinValFunction) (szFieldValue);
                }

                psrFieldDefinitionPtr->inFieldFullSize = 101; //Indicates a modified field
                //pdebug (("inRetVal=%d",inRetVal));
                if (inRetVal == VS_SUCCESS) {
                    switch (psrFieldDefinitionPtr->ucFieldType) {
                    case    FLD_BYTE:
                        if (atoi(szFieldValue) <= MAX_BYTE)
                            *(int *) pchValuePtr = atoi(szFieldValue);
                        else
                            inRetVal = VS_ERROR;
                        break;

                    case    FLD_CHAR:
                        *pchValuePtr = szFieldValue[0];
                        break;

                    case    FLD_SHORT:
                        if (atoi(szFieldValue) <= MAX_INT)
                            *(short *) pchValuePtr = (short) atoi(szFieldValue);
                        else
                            inRetVal = VS_ERROR;
                        break;

                    case    FLD_INT:
                        if (atoi(szFieldValue) <= MAX_INT)
                            *(int *) pchValuePtr = atoi(szFieldValue);
                        else
                            inRetVal = VS_ERROR;
                        break;

                    case    FLD_LONG:
                        if (atol(szFieldValue) <= MAX_LONG)
                            *(long *) pchValuePtr = atol(szFieldValue);
                        else
                            inRetVal = VS_ERROR;
                        break;

                    case    FLD_DBL:
                        *(double *) pchValuePtr = atof(szFieldValue);
                        break;

                    case    FLD_BIT:
                        //                            pdebug (("FLD_BIT - inEditField"));
                        memcpy(&TempBitsVal, pchValuePtr, INT_SIZE);
                        //                            pdebug (("TempBitsVal=%x",TempBitsVal));
                        /* Preserve all original bits and turn OFF the one being examined */
                        BitFieldValue = TempBitsVal & ~(1 << psrFieldDefinitionPtr->inFieldBitNum);
                        /* Set the bit being examined ON or OFF depending on user's choice */
                        BitFieldValue |= (szFieldValue[0] - '0') << psrFieldDefinitionPtr->inFieldBitNum;
                        //                            pdebug (("BitFieldValue=%x",BitFieldValue));
                        memcpy(pchValuePtr, &BitFieldValue, INT_SIZE);
#ifdef _TARG_68000
                        //                            BitFieldValue = *(short *)pchValuePtr & ~(1 << psrFieldDefinitionPtr->inFieldBitNum);
                        /* Set the bit being examined ON or OFF depending on user's choice */
                        //                            BitFieldValue |= (szFieldValue[0] - '0') << psrFieldDefinitionPtr->inFieldBitNum;
                        //                            *(short *)pchValuePtr = BitFieldValue;
#endif
#ifdef __arm
                        //                            BitFieldValue = *(int *)pchValuePtr & ~(1 << psrFieldDefinitionPtr->inFieldBitNum);
                        /* Set the bit being examined ON or OFF depending on user's choice */
                        //                            BitFieldValue |= (szFieldValue[0] - '0') << psrFieldDefinitionPtr->inFieldBitNum;
                        //                            *(int *)pchValuePtr = BitFieldValue;
#endif
                        break;

                    case    FLD_STR:
                        strlcpy(pchValuePtr, szFieldValue, psrFieldDefinitionPtr->inFieldSize);
                        break;

                    default:
                        break;
                    } /* switch */
                } /* if */
            } /* else if */

            if (inRetVal != VS_SUCCESS) {
                vdDisplayMessageFromFile((lnGGErrorMessage() > 0L ? lnGGErrorMessage() : VALIDATE_ERR_MSG), WARNING_MSG);
                vdSGErrorMessage(0L);
                continue;
            } else if (inResult >= 0) {
                /*
                 *  field valid, and was touched...
                 */
                (*inFieldChgd) = 1;
            }
            break;  /* exit while loop */
        } /* while */
    } /* if */
    else
        ;pdebug(("!ValidList !ValidNode"));

    return(inResult);
} /* End of inEditField() */


int inEditRecord(RecordList* prlRecordList,Node* pndSelectedRecord) {
    char szLineBuf[4][MESSAGE_SIZE + 1];

    int inResult = VS_FAILURE;
    int inFieldChgd = 0;
    int inSelectKey;
    VS_BOOL fTempMegaPW;
    FieldNode* pfnSelectedField;
    RecordList* pflFieldList;
    char* chNull = 0;

    //pdebug(("--inEditRecord--"));

    if (fValidList((List *) prlRecordList) && fValidNode((Node *) pndSelectedRecord)) {
        //Removed wait... due to faster terminal
        //vdDisplayMessageFromFile( LAN_WAIT_ERR_MSG, STATUS_MSG);
        LOG_PRINTFF((0x8L, "A"));

        if ((inResult = inCreateFieldList(prlRecordList, (RecordNode *) pndSelectedRecord, (PFB_FL_IN) NULL, (FieldList * *) &pflFieldList)) == VS_SUCCESS) {
            /* 3200: parse keys, display in right window */
            vdLoad3200Opt(szLineBuf, O3200_TBL_EDIT_KEYS_MSG);
            vdCreateOptWin3200(szLineBuf);
            pfnSelectedField = (FieldNode *) pndListStart((List *) pflFieldList);
            while ((inSelectKey = inSelectEditNode(pflFieldList, (Node * *) &pfnSelectedField, vdDisplayFieldNode)) == KEY_CR) {
                inEditField((FieldList *) pflFieldList, pfnSelectedField, &inFieldChgd);
                /* 3200: parse keys, display in right window */
                vdLoad3200Opt(szLineBuf, O3200_TBL_EDIT_KEYS_MSG);
                vdCreateOptWin3200(szLineBuf);
            }
            vdDestroyOptWin3200();
            if (inSelectKey == KEY_BS) {
                /*
                         *      Clear leftover Screen data
                         */ {
                    int x1,
                    y1,
                    x2,
                    y2;

                    wherewin(&x1, &y1, &x2, &y2);
                    window(x1, y1 + (obDisp.inCharsPerColumn == 4 ? 1 : 2), x2, y2);
                    clrscr();
                    window(x1, y1, x2, y2);
                }
                if (obDisp.inDO_ChooseOne(chNull, pchGetMsg(SAVE_CHANGES_MSG15), pchGetMsg(CANCELOK_MSG5x), 2, NULL_PFI) == KEY_OK) {
                    /*
                     *      Prevent Mega Password from becoming Locked on, yet leave it active for
                     *      entire 'Other Setup' editing session.
                     */
                    fTempMegaPW = fGetMegaPassword();
                    vdSetMegaPassword(VS_FALSE);
                    inResult = inSaveConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize, ((RecordNode *) pndSelectedRecord)->inRecordIndex, prlRecordList->pchRecordPtr);
                    vdSetMegaPassword(fTempMegaPW);

                    vdUpdateExpConfigLabels((List *) pflFieldList);  //Update exp config variable

                    //pdebug(("inResult = %d", inResult));
                } else {
                    inLoadConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize, ((RecordNode *) pndSelectedRecord)->inRecordIndex, prlRecordList->pchRecordPtr);
                    vdValidateValidationInitializations((List *) pflFieldList);
                }
            } else if (inSelectKey == KEY_CANCEL) // BJD: KEY_CLR -> KEY_CANCEL
            {
                if (inFieldChgd) {
                    if (obDisp.inDO_ChooseOne(chNull, pchGetMsg(SAVE_CHANGES_MSG15), pchGetMsg(CANCELOK_MSG5x), 2, NULL_PFI) == KEY_OK) {
                        /*
                         *      Prevent Mega Password from becoming Locked on, yet leave it active for
                         *      entire 'Other Setup' editing session.
                         */
                        fTempMegaPW = fGetMegaPassword();
                        vdSetMegaPassword(VS_FALSE);
                        inResult = inSaveConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize, ((RecordNode *) pndSelectedRecord)->inRecordIndex, prlRecordList->pchRecordPtr);
                        vdSetMegaPassword(fTempMegaPW);
                        /* save terminal beep value selected by user */
                        key_beeps((short) fGetTerminalBeep());

                        vdUpdateExpConfigLabels((List *) pflFieldList);  //Update exp config variable
                    } else {
                        inLoadConfRec(prlRecordList->pszFileName, prlRecordList->inRecordSize, ((RecordNode *) pndSelectedRecord)->inRecordIndex, prlRecordList->pchRecordPtr);
                        vdValidateValidationInitializations((List *) pflFieldList);
                        inResult = VS_ESCAPE;
                    }
                } else
                    inResult = VS_ESCAPE;
            }
            vdDestroyListAndNodes((List *) pflFieldList);
        }
    }
    return(inResult);
}

/*-------------------------------------------------------------------------
    Function :    inConfRecEdit
    Description : Goes through the configuration tables, allows the user to edit
                  informations that can be changed, record by record, prompts the user to
                  save the information and saves it.
    Parameters :
    Returns :
              VS_ERR     on any error
              VS_SUCCESS on SUCCESS
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      0   10/26/95 T_Al_G     Created a new version.
      1   06/21/96 Pat_G1     Removed call to inGetRecordDescriptor because
                              it allocated space on the heap for
                              psrFieldDefinitionPtr. Function
                              inCreateRecordList calls inGetRecordDescriptor
                              so it was changed so that it doesn't free
                              the allocation of the FieldDefinition pointer.
--------------------------------------------------------------------------*/
int inConfRecEdit(const char* pchDataFileName) {
    char szLineBuf[4][MESSAGE_SIZE + 1];
    int inResult = 0;
    Node* pndSelectedRecord;
    RecordList* prlRecordList;
    int inOptCreated = 0;

    //pdebug (("--inConfRecEdit"));

    obDisp.blCfigEdit = VS_TRUE;

    // Removed check for SKE file and setting FTag

    // Removed wait... due to faster terminal
    // vdDisplayMessageFromFile( WAIT_MSG, STATUS_MSG);
    if ((inResult = inCreateRecordList(pchDataFileName, &prlRecordList, (PFI_RL_IN_IN_CP) NULL, -1, (char *) NULL)) >= VS_SUCCESS) {
        /* 3200: parse keys, display in right window */
        vdLoad3200Opt(szLineBuf, O3200_TBL_CHOOSE_KEYS_MSG);
        vdCreateOptWin3200(szLineBuf);
        inOptCreated = 1;
        pndSelectedRecord = pndListStart((List *) prlRecordList);

        while (inSelectNode(prlRecordList, (Node * *) &pndSelectedRecord, vdDisplayRecordNode) == KEY_CR) {
            if ((inResult = inEditRecord(prlRecordList, pndSelectedRecord)) != VS_SUCCESS)
                break;

            /* 3200: parse keys, display in right window */
            vdLoad3200Opt(szLineBuf, O3200_TBL_CHOOSE_KEYS_MSG);
            vdCreateOptWin3200(szLineBuf);
        }
        vdFree((char *) prlRecordList->psrFieldDefinitionPtr);   /* Allocated in inGetRecordDescriptor() */
        vdFree(prlRecordList->pchRecordPtr);    /* Allocated in inCreateRecordList() */
        vdDestroyListAndNodes((List *) prlRecordList);   /* Allocated in pliCreateList()/pndCreateNode() */
    }

    if (inOptCreated)
        vdDestroyOptWin3200();

    obDisp.blCfigEdit = VS_FALSE;

    return(inResult);
}

/*
 * Calls the inConfRecEdit() function with BAT_INDEX, but sets the online or
 * offline flag.
 * Preconditions:
 *         1. The cdt host index should be set to the appropriate value.
 *         2. Corresponfing HDT should be loaded
 * Returns
 *             VS_ERR on any error
 *             VS_SUCCESS on SUCCESS
 */
int inBatchRecEdit() {
    //pdebug(("--inBatchRecEdit--"));
#ifdef NOT_IMPLEMENTED_YET
    return(inConfRecEdit(BAT_INDEX));
#endif
    return (VS_SUCCESS);
}

/*
 *      This function runs through the linked list of fields and re-runs the validation/initialization functions
 *      for fields with validation functions that were modified to return the terminal to inits original state
 *      in case modifications were CANCELLED.
 */
void vdValidateValidationInitializations(List* pliListOfChoices) {
    Node* pndCurrentNode;
    FieldList* pflFieldList;
    FieldNode* pfnSelectedField;
    FieldDefinition* psrFieldDefinitionPtr;
    long FieldDefSize = REC_SIZEOF(FieldDefinition);
    PFI_PSZ pinValFunction;
    int inFieldID;
    char szFieldValue[MAX_CONFIG_FIELD_SIZE + 1];

    pflFieldList = (FieldList *) pliListOfChoices;
    pndCurrentNode = pndListStart((List *) pliListOfChoices);
    do {
        pfnSelectedField = (FieldNode *) pndCurrentNode;
        //        psrFieldDefinitionPtr = &pflFieldList->prlParentRecord->psrFieldDefinitionPtr[pfnSelectedField->inFieldIndex];
        psrFieldDefinitionPtr = (FieldDefinition *) ((unsigned char *) pflFieldList->prlParentRecord->psrFieldDefinitionPtr + (pfnSelectedField->inFieldIndex * FieldDefSize));

        if (psrFieldDefinitionPtr->inFieldFullSize == 101) {
            vdGetFieldNodeValue(pflFieldList->prlParentRecord, pfnSelectedField->inFieldIndex, szFieldValue);

            if (psrFieldDefinitionPtr->shFieldFuncID != NO_VALIDATION) {
                inFieldID = (int) psrFieldDefinitionPtr->shFieldFuncID;
                if ((pinValFunction = (PFI_PSZ) inGetFunctionPointer(inFieldID)) != NULL)
                    (pinValFunction) (szFieldValue);
            }
        }

        pndCurrentNode = pndNextNode(pndCurrentNode);
    } while (pndCurrentNode != NULL_CH);
} /* End of vdValidateValidationInitializations() */

// Sadiq - Added new function to update express config variables
// when table field values are changed thru other setup.

void vdUpdateExpConfigLabels(List* pliListOfChoices) {
    Node* pndCurrentNode;
    FieldList* pflFieldList;
    FieldNode* pfnSelectedField;
    FieldDefinition* psrFieldDefinitionPtr;
    long FieldDefSize = REC_SIZEOF(FieldDefinition);
    char szFieldValue[MAX_CONFIG_FIELD_SIZE + 1];
    int inRecNum;
    char szFieldLabel[MAX_CONFIG_NM_SIZE + 1];
    char szRecNum[5];

    pflFieldList = (FieldList *) pliListOfChoices;
    pndCurrentNode = pndListStart((List *) pliListOfChoices);
    do {
        pfnSelectedField = (FieldNode *) pndCurrentNode;
        //        psrFieldDefinitionPtr = &pflFieldList->prlParentRecord->psrFieldDefinitionPtr[pfnSelectedField->inFieldIndex];
        psrFieldDefinitionPtr = (FieldDefinition *) ((unsigned char *) pflFieldList->prlParentRecord->psrFieldDefinitionPtr + (pfnSelectedField->inFieldIndex * FieldDefSize));

        if ((psrFieldDefinitionPtr->inFieldFullSize == 101) && (strlen(psrFieldDefinitionPtr->szFieldLabel) > 0)) {
            strcpy(szFieldLabel, psrFieldDefinitionPtr->szFieldLabel);
            inRecNum = pflFieldList->inRecordNumber + 1;
            sprintf(szRecNum, "%d", inRecNum);
            strcat(szFieldLabel, szRecNum);
            vdGetFieldNodeValue(pflFieldList->prlParentRecord, pfnSelectedField->inFieldIndex, szFieldValue);
            put_env(szFieldLabel, szFieldValue, strlen(szFieldValue));
        }

        pndCurrentNode = pndNextNode(pndCurrentNode);
    } while (pndCurrentNode != NULL_CH);
} /* End of vdUpdateExpConfigLabels  */

short shListEntry(const ListEntry* leList,short shListSz,char* szFieldValue) {
    short index = 0;
    short shKey;
    short shRetVal = VS_FAILURE;
    char szDisplayMsg[MESSAGE_SIZE + 1];
    char szLineBuf[4][MESSAGE_SIZE + 1];

    //pdebug (("shListEntry"));

    vdGetMessageFromFile(NEWVAL_MSG15, szDisplayMsg);
    vdDisplayAt(obDisp.inHomeCol, obDisp.inInputLine, szDisplayMsg, NO_CLEAR);
    vdLoad3200Opt(szLineBuf, O3200_TBL_CHOOSE_KEYS_MSG);
    vdCreateOptWin3200(szLineBuf);

    while (1) {
        vdDisplayAt(obDisp.inHomeCol, obDisp.inInputLine + 1, (char *) leList[index].szText, CLR_EOL);

        shKey = inWaitKey(inGetIdleTimeOut());
        //pdebug(("shKey=%d",shKey));
        if (shKey == KEY_e)      /* PREV selected */ {
            if (index == 0)
                index = (shListSz - 1);
            else
                index--;
        } else if (shKey == KEY_f)      /* NEXT selected */ {
            if (index == (shListSz - 1))
                index = 0;
            else
                index++;
        } else if (shKey == KEY_g ||   /* Take selected */
                   shKey == KEY_CR) {
            //pdebug(("index=%d",index));
            int2str(szFieldValue, leList[index].shValue);
            shRetVal = VS_SUCCESS;
            break;
        } else if (shKey == KEY_h ||   /* EXIT */
                   shKey == KEY_CANCEL)
            break;
        else
            vdBeep();
    }

    return shRetVal;
}

short shChoiceEntry(const ListEntry* leList,short shListSz,char* szFieldValue) {
    int i;
    short shKey;
    short shRetVal = VS_FAILURE;
    char szLineBuf[4][MESSAGE_SIZE + 1];

    memset(szLineBuf, 0, ((MESSAGE_SIZE + 1) * 4));
    for (i = 0; i < shListSz; ++i) {
        strcpy(szLineBuf[i], leList[i].szText);
    }

    vdDestroyOptWin3200();  /* reset option window */
    vdCreateOptWin3200(szLineBuf);

    while (1) {
        shKey = inWaitKey(inGetIdleTimeOut());
        //pdebug(("shKey=%d",shKey));
        if (shKey == KEY_e) {
            int2str(szFieldValue, leList[0].shValue);
            shRetVal = VS_SUCCESS;
            break;
        } else if (shKey == KEY_f) {
            int2str(szFieldValue, leList[1].shValue);
            shRetVal = VS_SUCCESS;
            break;
        } else if (shKey == KEY_g && shListSz >= 3) {
            int2str(szFieldValue, leList[2].shValue);
            shRetVal = VS_SUCCESS;
            break;
        } else if (shKey == KEY_h && shListSz == 4) {
            int2str(szFieldValue, leList[3].shValue);
            shRetVal = VS_SUCCESS;
            break;
        } else if (shKey == KEY_CANCEL) /* ESC hit */
            break;
        else
            vdBeep();
    }

    vdDestroyOptWin3200();  /* reset option window */
    return shRetVal;
}

int SCALLS_CODE_CHECK(char* a,char* b,short * c,char* d,unsigned char* e) {
    GET_VER(a, b, c, d, e);
    return 1;
}

#undef VSSCALLS_C

